function [y] = equity_update(bParams,oParams,f,c,lambda,equity,bin_prob,q_mat)
% Updates the equity value using a rewritten version of the HJB equation.

% Variables:
% bParams,oParams	see readme
% f			rate of creative destruction
% c			coupon
% lambda	R&D intensity
% equity	equity value
% bin_prob	transition probabilities
% q_mat		realized R&D costs

% Set parameters
	pbar = oParams.pbar;
	r = oParams.r;
	pi = oParams.pi;
	pvec = (0:pbar);
	eta = bParams.eta;

% Update equity value using HJB equation
	y = ( (1-pi) * (pvec - c - eta - q_mat) + lambda .* (bin_prob * equity')' + f * pvec .* [0 equity(1:pbar)] )./ (r + lambda + pvec * f);

% Optimal default
	y = max(real(y),0);
	y(1) = 0;

end
